<?php
MYDCONN();
	if(!isset($_POST['RsSetProfit'])) { $_POST['RsSetProfit'] = 0;}
	if($_POST['RsID'.$_POST['RsCount']]>0) {
		for($i=1;$i<=$_POST['RsCount'];$i++) {
		if($_POST['RsID'.$i]>0) {
		$GLOBALS['MYD']->db_query("UPDATE finantial_results SET RsOffice = {$_POST['RsOffice'.$i]}, RsAmount = {$_POST['RsAmount'.$i]} WHERE RsID = {$_POST['RsID'.$i]}");
		}else {
		$GLOBALS['MYD']->db_query("INSERT INTO finantial_results (RsOri,RsDate,RsType,RsAmount,RsProfit,RsOffice) VALUES ({$_POST['OriNumero'.$i]},'{$_POST['RsDate']}',{$_POST['RsType']},{$_POST['RsAmount'.$i]},{$_POST['RsSetProfit']},{$_POST['RsOffice'.$i]})");
		}
		}
	} else {
		$RsString = 'INSERT INTO finantial_results (RsOri,RsDate,RsType,RsAmount,RsProfit,RsOffice) VALUES ';
		for($i=1;$i<=$_POST['RsCount'];$i++) {
		$RsString .= "({$_POST['OriNumero'.$i]},'{$_POST['RsDate']}',{$_POST['RsType']},{$_POST['RsAmount'.$i]},{$_POST['RsSetProfit']},{$_POST['RsOffice'.$i]}),";
		}
		$GLOBALS['MYD']->db_query(substr($RsString,0,strlen($RsString)-1));
	} 
	echo '<div class="Confirm">Guardado.</div>';